def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

number = input("Введите четырёхзначное число: ")
max_prime = 0

if number.isdigit() and number!=0:
    for i in range(4):
        for j in range(i+1, 5):
            sub_number = int(number[i:j])
            if is_prime(sub_number):
                max_prime = max(max_prime, sub_number)

print(max_prime if max_prime else 0)
